package com.sinkdream.cms.controller;

import com.sinkdream.cms.VO.LoginVO;
import com.sinkdream.cms.result.CodeMsg;
import com.sinkdream.cms.result.Result;
import com.sinkdream.cms.service.UserService;
import com.sinkdream.cms.util.ValidatorUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.validation.Valid;

@Controller
@CrossOrigin
@RequestMapping("/user")
public class UserController {
    private static Logger log = LoggerFactory.getLogger(UserController.class);

    @Autowired
    UserService userService;

    /*
    用户注册功能
     */
    public Result<Boolean> userRegister(){
        return null;
    }

    /*
    用户登录功能
     */
    @RequestMapping("/login")
    public Result<Boolean> userLogin(@Valid LoginVO loginVO){
        log.info(loginVO.toString());
        CodeMsg cm = userService.userLogin(loginVO);
        if(cm.getCode() == 1) {
            return Result.success(true);
        }else{
            return Result.error(cm);
        }
    }


}
